<?php
namespace app\admin\controller;
use app\admin\logic\ClassLearnRecordLogic;

/**
 * 学习记录api控制器
 * Created by PhpStorm.
 * User: tyll
 * Date: 2019/10/22
 * Time: 15:08
 */
class ClassLearnRecord extends Base {

    public $clid = 1;

    public function __construct(){
        parent::__construct();
        $this->ct_logic = new ClassLearnRecordLogic();
    }

    /**
     * 获取学习记录
     * @return \think\response\Json
     */
    public function ajax_get_clr(){
        $params = input();
        $r = $this->check_admin_token($params);
        if ($r['code'] != 1) {
            return json($r);
        }

        $maps = $this->ct_logic->get_search_clr_maps($this->clid,$params['username'],$params['start_time'],$params['end_time']);
        $limit = ($params['page'] - 1) * $params['rows'];

        $list = model('class_learn_ci')->get_list($maps,'id,openid,right_num,wrong_num,score,zeng_score,start_time','id desc','',$limit,$params['rows']);
        foreach($list as $k => $v){
            $u_maps = [];
            $u_maps[] = ['openid','=',$v['openid']];
            $u_detail = model('user')->get_detail($u_maps,'id,username');
            $list[$k]['username'] = $u_detail['username'];
        }

        $total_num = model('class_learn_ci')->get_count($maps,'id');

        $data['list'] = $list;
        $data['total_num'] = $total_num;
        return json($this->ct_logic->get_response(1,'OK',$data));
    }
}